#include <jni.h>
#include <stdlib.h>
#include "../file/android_fopen.h"
#include "string_util.h"

JNIEXPORT jstring JNICALL
Java_com_xiaoyu_base_utils_KeyUtil_content(JNIEnv *env, jobject instance, jobject asset_manager, jstring filename) {
    char *content = "";

    FILE *file = android_assets_fopen(env, asset_manager, filename);
    if (!file) {
        return (*env)->NewStringUTF(env, content);
    }
    char buffer[1024];

    while (fgets(buffer, 1024, file)) {
        content = join(content, buffer);
    }

    fclose(file);
    return convertToJstringWithUTF(env, content);
}

JNIEXPORT jstring JNICALL
Java_com_xiaoyu_base_utils_KeyUtil_key(JNIEnv *env, jobject instance, jobject asset_manager) {
    jstring filename = (*env)->NewStringUTF(env, "logo.png");
    jstring source = Java_com_xiaoyu_base_utils_KeyUtil_content(env, instance, asset_manager, filename);
    jstring regx = (*env)->NewStringUTF(env, "yizhoupk:");
    jstring result = splitJstring(env, source, regx);
    return result;
}


